package com.uncheck;

import com.alibaba.fastjson.JSONObject;
import com.alibaba.fastjson.serializer.SerializeConfig;
import com.alibaba.fastjson.serializer.SerializerFeature;
import com.alibaba.fastjson.serializer.SimpleDateFormatSerializer;

import okhttp3.*;


import java.util.*;


public class HttpService {


    /**
     * object转json,处理时间格式
     */
    private String convertJson(Object dto) {
        SerializeConfig config = new SerializeConfig();
        config.put(Date.class, new SimpleDateFormatSerializer("yyyy-MM-dd HH:mm:ss"));
        String json = JSONObject.toJSONString(dto, config, SerializerFeature.WriteMapNullValue);
        return json;
    }

    /**
     * send http connection
     */
    private Boolean okPost(String json) {
        OkHttpClient client = new OkHttpClient();
        String type = "application/json;charset=utf-8";
        String url = "";
        RequestBody param = RequestBody.create(MediaType.parse(type), json);
        Request request = new Request.Builder().url(url).post(param).build();
        Boolean flag = false;
        try (Response response = client.newCall(request).execute()) {
            flag = response.code() == 200;
        } catch (Exception e) {
            e.printStackTrace();
        }
        return flag;
    }


}
